package com.htiiot.elasticsearch;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.multibindings.Multibinder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.repositories.RepositoriesModule;
import org.elasticsearch.rest.BaseRestHandler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * elasticsearch5.x ID自增插件
 *
 * @author 李延念
 * @create 2018-06-29 11:16
 **/
public class ESPluginRun5 extends Plugin {
    private final static Logger logger = LogManager.getLogger(ESPluginRun5.class);
    private final Settings settings;

    public ESPluginRun5(Settings settings) {
        this.settings = settings;
    }
    @Override
    public Collection<Module> createGuiceModules() {
        return Collections.<Module>singletonList(new ConfiguredModule());
    }
    @Override
    @SuppressWarnings("rawtypes") // Plugin use a rawtype
    public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
        Collection<Class<? extends LifecycleComponent>> services = new ArrayList<>();
        return services;
    }

    public void onModule(RepositoriesModule repositoriesModule) {
    }
    @Override
    public Settings additionalSettings() {
        return Settings.EMPTY;
    }
    /**
     * Module declaring some example configuration and a _cat action that uses
     * it.
     */
    public static class ConfiguredModule extends AbstractModule {
        @Override
        protected void configure() {
            //bind(ExamplePluginConfiguration.class).asEagerSingleton();
            Multibinder<BaseRestHandler> catActionMultibinder = Multibinder.newSetBinder(binder(), BaseRestHandler.class);
            catActionMultibinder.addBinding().to(HTRestIndexAction5.class).asEagerSingleton();
        }
    }
}
